var myData = {}
myData["getTree"] = function (key, callback) {
    pywebview.api.getTree3(key).then(function (response) {

        callback(response)
    });
}
myData["getFile"] = function (path, callback) {

    pywebview.api.getFile(path).then(function (response) { callback(response) });
}

myData["addNasInfo"] = function (item, callback) {
    pywebview.api.addNasInfo(item).then(function (response) { callback(response) });
}
myData["addNasInfos"] = function (item, callback) {
    pywebview.api.addNasInfos(item).then(function (response) { callback(response) });
}

myData["getNasInfosByFolder"] = function (nas_abs_folder_path, callback) {
    pywebview.api.getNasInfosByFolder(nas_abs_folder_path).then((response) => { callback(response) });
}
myData["getNasInfosBySame"] = function (nas_abs_file_path, callback) {
    pywebview.api.getNasInfosBySame(nas_abs_file_path).then((response) => { callback(response) });
}


myData["getSltKeySearch"] = (param, callback) => {
    pywebview.api.getSltKeySearch(param).then((response) => { callback(response) });
}
myData["getNasFileExt"] = (callback) => {
    pywebview.api.getNasFileExt().then((response) => { callback(response) });
}
myData["getLoadFileName"] = (callback) => {
    pywebview.api.getLoadFileName().then((response) => { callback(response) });
}
myData["openFileFromExplorer"] = (nas_abs_file_path) => {
    pywebview.api.openFileFromExplorer(nas_abs_file_path).then((response) => { });
}

myData["delFile"] = (nas_abs_file_path, nas_abs_file_raw_path, callback) => {
    pywebview.api.delFile(nas_abs_file_path, nas_abs_file_raw_path).then((response) => { callback(response) });
}
myData["safeFolderPwd"] = (pwd, callback) => {
    pywebview.api.safeFolderPwd(pwd).then((response) => {
        if (response) {
            callback();
            myData["setSession"]("safeFolderPwd", { "result": "good" });
        } else { alert("密码错误"); myData["removeSession"](safeFolderPwd)}
    });
}
myData["removeSession"] = (key) => {
    key = key.replaceAll("\\\\", "/");
    key = key.replaceAll("\/", "_");
    sessionStorage.removeItem(md5(key));
};
myData["getSession"] = (key) => {
    key = key.replaceAll("\\\\", "/");
    key = key.replaceAll("\/", "_");
    var result = JSON.parse(sessionStorage.getItem(md5(key)));
    return result;
}
myData["setSession"] = (key, item) => {
    key = key.replaceAll("\\\\", "/");
    key = key.replaceAll("\/", "_");
    sessionStorage.setItem(md5(key), JSON.stringify(item));
}


myData["setSession"]("safeFolderPwd", { "result": "good" });

var asyncFlag = false;
async function asyncDelayedLoop(callback) {
    while (true) {
        if (asyncFlag) {
            break;
        }
        callback();
        await new Promise(resolve => setTimeout(resolve, 400)); // 等待指定的延时后继续执行下一轮循环
    }
}